package com.kehao.leetcode.jzoffer;

import java.util.TreeMap;

public class JZSolution058 {

    private static class MyCalendar{
        private TreeMap<Integer,Integer> startToEndMap;

        public MyCalendar() {
            startToEndMap = new TreeMap<>();
        }

        public boolean book(int start, int end) {
            Integer ceil = startToEndMap.ceilingKey(start);
            if(ceil!=null&&ceil<end){
                return false;
            }
            Integer floor = startToEndMap.floorKey(start);
            if(floor!=null&&startToEndMap.get(floor)>start){
                return false;
            }
            startToEndMap.put(start,end);
            return true;
        }
    }

}
